import React, { useState, useEffect } from 'react';
import DocumentTitle from 'react-document-title'

import { certification } from '@api/auth';

import Application from './component/application'
import CheckStatus from './component/checkstatus'
import { useSelector } from 'react-redux';




const Authentication = (props) => {

  const appConfig = useSelector(state => state.appConfig)

  // 0待提交 1审核通过 2拒绝 -1提交
  // 等待校验银行卡 & -1
  //  type 0未打款  1验证  2验证通过
  const [checkStatus, setCheckStatus] = useState(null)
  const [waitCheckBank, setWaitCheckBank] = useState(null)

  useEffect(() => {

    certification( appConfig.uniacid ).then(res => {

      let status = parseInt(res.data.status)
      let type = parseInt(res.data.type)

      setCheckStatus(status)
      setWaitCheckBank(type)

    })
  }, [checkStatus, waitCheckBank,appConfig ])

  return (
    <>
      <DocumentTitle title={props.route.title} />
      {
        checkStatus === 0 ? <Application /> : <CheckStatus status={checkStatus} bankStatus={waitCheckBank} />
      }
    </>
  )

}


export default Authentication